package com.xh.java_mybatis_xml_config_mybatis_config_demo.controller;


import com.xh.java_mybatis_xml_config_mybatis_config_demo.entity.TUser;
import com.xh.java_mybatis_xml_config_mybatis_config_demo.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class TUserController {

    @Autowired
    private TUserMapper tUserMapper;

    @GetMapping(value = "/getTUser")
    public List<TUser> getTUser() {
        //TODO
        List<TUser> tUsers = tUserMapper.selectAllTUsers();
        for (TUser tUser : tUsers) {
            System.out.println(tUser);
        }
        System.out.println("测试接口-查询表中所有数据，数据个数："+tUsers.size());
        return tUsers;

    }

    @PostMapping(value = "/addTUser")
    public void addTUser(@RequestBody TUser tUser) {
        //TODO
        tUserMapper.insertTUser(tUser);
    }

    @PutMapping(value = "/updateTUser")
    public void updateTUser(@RequestBody TUser tUser) {
        //TODO
//        String username = tUser.getUsername();
        tUserMapper.updateTUser(tUser);
    }

    @DeleteMapping(value = "/removeTUser")
    public void removeTUser(@RequestParam("id")int id) {
        //TODO
        tUserMapper.deleteTUser(id);
    }

}
